<!-- techSetting -->
<template>
  <div class="techSetting content_box">
    <div class="m-b-1 flex align-center space-between">
      <el-button type="success" @click="(showForm = true), (currentItem = {})">添加按钮</el-button>
    </div>
    <el-table class="m-b-1" v-loading="listLoading" :data="list" @sort-change="sortChange" border style="width: 100%">
      <el-table-column type="index" label="序号" align="center" fixed>
      </el-table-column>
      <el-table-column prop="BtnName" label="按钮名称" align="center" />
      <el-table-column prop="BtnCode" label="按钮编码" align="center" />
      <el-table-column label="操作" align="center" width="180" fixed="right">
        <template slot-scope="{ row }">
          <el-button size="mini" type="danger" @click="$delConfirm(() => del(row.Id))">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <SystemButtonForm :menu-id="menuId" :show.sync="showForm" :form-data="currentItem" @finish="getList"></SystemButtonForm>
  </div>
</template>

<script>
  import { getSystemButton, delSystemButton } from '@/api/system/system-button'
  import Pagination from '@/components/Pagination'
  import SystemButtonForm from './components/SystemButtonForm'
  import { deepClone } from '@/utils'
  import { mapState } from 'vuex'
  export default {
    //import引入的组件需要注入到对象中才能使用
    name: 'systemButton',
    components: { Pagination, SystemButtonForm },
    props: {
      menuId: {
        default() {
          return ''
        }
      }
    },
    data() {
      //这里存放数据
      return {
        showForm: false,
        currentItem: {},
        list: null,
        total: 0,
        listLoading: true,
        searchObjTmpl: {},
        searchObj: {
          Sname: '',
          IsDirect: '',
          IsActive: '',
          CostName: '',
          StartTime: '',
          EndTime: ''
        },
        listQuery: {
          IsPaging: false, //是否分页
          SortName: 'CreateDate',
          SortType: false
        },
      };
    },
    //监听属性 类似于data概念
    computed: {
      dialogTitle() {
        return this.dialogType == 'add' ? '新增技术服务年费信息方案' : '编辑技术服务年费信息方案'
      },
    },
    //监控data中的数据变化
    watch: {
      menuId: {
        handler(val) {
          this.resetFilter()
        }
      }
    },
    // 生命周期 - 创建完成（可以访问当前this实例）
    created() {
      this.searchObjTmpl = deepClone(this.searchObj)
      this.getList()
    },
    activated() { },
    //方法集合
    methods: {
      resetFilter() {
        this.searchObj = deepClone(this.searchObjTmpl)
        this.handleFilter()
      },
      sortChange(data) {
        const { prop, order } = data
        this.listQuery.SortName = prop
        if (order === 'ascending') {
          this.listQuery.SortType = true
        } else {
          this.listQuery.SortType = false
        }
        this.handleFilter()
      },
      handleFilter() {
        this.listQuery.PageIndex = 1
        this.getList()
      },
      getQuery() {
        const params = {
          ...this.searchObj,
          ...this.listQuery,
        }
        for (let i in params) {
          if (params[i] === '') {
            delete params[i]
          }
        }
        params.MenuId = this.menuId
        return params
      },
      async getList() {
        this.listLoading = true
        const params = this.getQuery()
        // params.UserId = this.userId
        // params.ExtendId = this.userId
        const { Data, Total } = await getSystemButton(params)
        this.listLoading = false
        this.list = Data || []
        this.total = Total || 0
      },
      async del(id) {
        const { code } = await delSystemButton({
          Id: id
        })
        if (code == 200) {
          this.$notify({
            title: '删除成功',
            message: 'success',
            type: 'success',
            duration: 2000
          })
          this.getList()
        }
      },
    },
  }
</script>
//@import url(); 引入公共css类
<style  scoped>
  .techSetting >>> .el-input-group__append {
    padding: 0 !important;
  }

  .tit_span {
    width: auto !important;
  }
  .sortInput {
    width: 22%;
  }
</style>
